﻿Public Class ExecuteAction

    Public Shared Function CanExecute(ByVal script As Script, ByVal connectionString As String) As Boolean
        Return script IsNot Nothing AndAlso Not String.IsNullOrEmpty(connectionString)
    End Function

    ''' <summary>
    ''' Executes the specified script
    ''' </summary>
    ''' <param name="script"></param>
    ''' <param name="connectionString"></param>
    ''' <remarks></remarks>
    Public Shared Sub Execute(ByVal scriptProject As ScriptProject, _
                              ByVal script As Script, _
                              ByVal connectionString As String)

        If scriptProject Is Nothing Then Throw New ArgumentNullException("scriptProject")
        If script Is Nothing Then Throw New ArgumentNullException("script")

        Execute(scriptProject, New Script() {script}, connectionString)

    End Sub

    Public Shared Function CanExecute(ByVal scripts As IEnumerable(Of Script)) As Boolean
        Return scripts IsNot Nothing AndAlso scripts.Count() > 0
    End Function

    ''' <summary>
    ''' Executes the specified list of scripts
    ''' </summary>
    ''' <param name="scripts"></param>
    Public Shared Sub Execute(ByVal scriptProject As ScriptProject, _
                              ByVal scripts As IEnumerable(Of Script), _
                              ByVal connectionString As String)

        If scriptProject Is Nothing Then Throw New ArgumentNullException("scriptProject")
        If scripts Is Nothing Then Throw New ArgumentNullException("scripts")

        'Create the window
        Dim window As New ScriptExecutorWindow(scriptProject, scripts, connectionString)

        'Show the dialog
        window.Show()
    End Sub
End Class
